<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
        <ui:define name="content">
            <h:form prependId="false" id="uplaodFileForm">
                <p:panel header="Unpaid Invoices" id="allinvoicespanel">
                    <p:messages />
                    <p:dataTable value="#{customerInvoiceEntityController.unpaidInvoices}" var="item">
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_id}"/>
                            </f:facet>
                            <h:outputText value="#{item.id}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_type}"/>
                            </f:facet>
                            <h:outputText value="#{item.type}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_status}"/>
                            </f:facet>
                            <h:outputText value="#{item.status}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_customerAccount}"/>
                            </f:facet>
                            <h:outputText value="#{item.customerAccount}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_amount}"/>
                            </f:facet>
                            <h:outputText value="#{item.amount}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_dueDate}"/>
                            </f:facet>
                            <h:outputText value="#{item.dueDate}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_createdAt}"/>
                            </f:facet>
                            <h:outputText value="#{item.createdAt}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_createdBy}"/>
                            </f:facet>
                            <h:outputText value="#{item.createdBy.fullname}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <p:commandButton image="ui-icon ui-icon-search" action="#{customerInvoiceEntityController.prepareView}" ajax="false">
                                <f:setPropertyActionListener target="#{customerInvoiceEntityController.current}" value="#{item}" />
                            </p:commandButton>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <p:menuButton value="Options" >
                                <p:menuitem value="payment" rendered="#{item.toBePaid}"
                                            action="#{customerInvoiceEntityController.doNothing}"
                                            update="@form:displayInvoice,@form:displayInvoiceCIA,@form:displayInvoiceReminder" oncomplete="paymentDialog.show()"
                                            process="@form">
                                    <f:setPropertyActionListener target="#{customerInvoiceEntityController.current}" value="#{item}" />
                                </p:menuitem>
                            </p:menuButton>
                        </p:column>
                    </p:dataTable>
                </p:panel>

                
                <p:dialog header="Make Payment" widgetVar="paymentDialog" width="800">  
                    <p:fieldset legend="Invoice Information">
                        <h:panelGroup id="displayInvoiceCIA" rendered="#{customerInvoiceEntityController.selected.CIA}">
                            <ui:include src="/entities/customerInvoiceEntity/ViewCIAInvoice.xhtml" />
                        </h:panelGroup>
                        <h:panelGroup id="displayInvoice" rendered="#{customerInvoiceEntityController.selected.normal}">
                            <ui:include src="/entities/customerInvoiceEntity/ViewNormalInvoice.xhtml" />
                        </h:panelGroup>
                        <h:panelGroup id="displayInvoiceReminder" rendered="#{customerInvoiceEntityController.selected.reminder}">
                            <ui:include src="/entities/customerInvoiceEntity/ViewReminderInvoice.xhtml" />
                        </h:panelGroup>
                    </p:fieldset>
                    <br />
                    <p:fieldset legend="Payment Information">  
                        <h:panelGrid columns="2" cellpadding="10">  
                            <h:outputText value="Payment Date: " />
                            <p:calendar value="#{customerInvoiceEntityController.paymentDate}" maxdate="#{salesQuotationEntityController.getToday()}"/>
                        </h:panelGrid>  
                    </p:fieldset> 
                    <br />
                    <p:commandButton value="record payment" action="#{customerInvoiceEntityController.recordPaymentAndView()}" ajax="flase"/>
                    &nbsp;
                    <p:commandButton value="record payment and close" action="#{customerInvoiceEntityController.recordPayment()}" update="@form:allinvoicespanel" oncomplete="paymentDialog.hide();"/>
                    &nbsp;
                    <p:commandButton value="cancel" onclick="paymentDialog.hide();" />
                </p:dialog>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
